package sajat.onlab;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.view.Window;
import android.widget.TextView;

public class MyFragmentActivity extends FragmentActivity {
	
	final int NUMBER_OF_PAGES = 2;
	TextView pagetext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.fragmentholder);
		
		pagetext = (TextView)findViewById(R.id.pagetext1);
		pagetext.setText(Html.fromHtml("<font color=#0000ff>.</font>"));
		for (int i=0; i<NUMBER_OF_PAGES-1; i++) {
			pagetext.append(".");
		}

		ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(),NUMBER_OF_PAGES);

		adapter.addFragment(new FriendListFragment());
		adapter.addFragment(new PoiListFragment());

		ViewPager pager = (ViewPager) findViewById(R.id.viewpager);

		pager.setAdapter(adapter);
		
		pager.setOnPageChangeListener(
				new OnPageChangeListener() {

					@Override
					public void onPageScrollStateChanged(int arg0) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void onPageScrolled(int arg0, float arg1, int arg2) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void onPageSelected(int arg0) {
						changeText(arg0);
						
					}
					
				}
				);

	}
	
	public void changeText (int pageselected) {
		pagetext.setText("");
		for (int i=0; i<pageselected; i++) {
			pagetext.append(".");
		}
		pagetext.append(Html.fromHtml("<font color=#0000ff>.</font>"));
		for (int i=pageselected+1; i<NUMBER_OF_PAGES; i++) {
			pagetext.append(".");
		}
	}

}
